<?php
Class String{


	public function __construct(){

	}

	public function abreviar($tamanhoMax,$valor,$nivel = 1, $ignoreFirstAndLastWord = true)
	{
		$nomes = explode(' ', $valor);
		$nomeAbv = $nomes;
		$tamanho = sizeof($nomes);
		$max = $tamanhoMax;
		$arrayResultante = array();
		$tamanhoStrings = strlen($valor);

		for ($i = 0 ; $i < $tamanho ; $i++)
		{
			if ($tamanhoStrings < $max)
			break;

			if ($ignoreFirstAndLastWord)
			{
				if (($i == 0) || ($i == $tamanho-1))
				{
					$nomeAbv[$i] = $nomes[$i];

					continue;
				}
			}
			$nomeAbv[$i] = substr($nomes[$i],0,$nivel);
			$tamanhoStrings = strlen(implode(' ', $nomeAbv));

		}
		$valor = implode(' ', $nomeAbv);
		return $valor;
	}


	public function formatar ($string, $tipo)
	{

		if ($tipo =='fone'){
			$string = '(' . substr($string, 0, 2) . ') ' . substr($string, 2, 4) . '-' . substr($string, 6);
		}else if($tipo =='cep'){
			$string = str_replace(",", "", $string);
			$string = str_replace(".", "", $string);
			$string = str_replace("/", "", $string);
			$string = str_replace("-", "", $string);

			$string = substr($string, 0, 5) . '-' . substr($string, 5, 9);

		}else if($tipo =='cpf'){
			$string = substr($string, 0, 3) . '.' . substr($string, 3, 3) . '.' . substr($string, 6, 3) . '-' . substr($string, 9, 2);

		}else if($tipo =='rg'){
			$string = substr($string, 0, 2) . '.' . substr($string, 2, 3) . '.' . substr($string, 5, 3);

		}

		return $string;
	}

	public function removerAcento($string){
		return   iconv('ASCII', 'UTF-8//IGNORE', $string);
	}



	public function recursive_array_search($needle,$haystack) {
		$needle = strtoupper($needle);
		foreach($haystack as $key=>$value) {
			$current_key=$key;
			if($needle===$value OR (is_array($value) && $this->recursive_array_search($needle,$value) !== false)) {
				return $current_key;
			}
		}
		return false;
	}

	public function removerAcentoBanco(){
		$tPessoa = new DbTable_Pessoa();
		$tPessoa->deletarAcento();

	}

	public function formatarData($data)
	{
		$data = explode('-', $data);
		$data = $data[2].'-'.$data[1].'-'.$data[0];

		return $data;
	}


}